import request from '@/utils/request'
import { praseStrEmpty } from "@/utils/ruoyi";

// 查询用户个人信息
export function getUserProfile() {
  return request({
    url: '/sys/user/admin/profile/getInfo',
    method: 'get'
  })
}

// 修改用户个人信息
export function updateUserProfile(data) {
  return request({
    url: '/sys/user/admin/profile/updateInfo',
    method: 'put',
    data: data
  })
}

// 用户头像上传
export function uploadAvatar(data) {
  return request({
    url: '/file/uploadHead',
    method: 'post',
    data: data
  })
}

// 通过id验证旧密码修改密码
export function updateUserPwd(oldPwd, pwd) {
  const data = {
    oldPwd,
    pwd
  }
  return request({
    url: '/sys/user/admin/profile/updatePwdByOldPwd',
    method: 'put',
    data: data
  })
}

// 新增用户
export function addUser(data) {
  return request({
    url: '/sys/user/admin/pwdRegister',
    method: 'post',
    data: data
  })
}

// 修改用户
export function updateUser(data) {
  return request({
    url: '/sys/user/admin/updateById',
    method: 'put',
    data: data
  })
}

// 查询用户列表
export function listUser(query) {
  return request({
    url: '/sys/user/admin/page',
    method: 'get',
    params: query
  })
}

// 导出用户
export function exportUser(query) {
  return request({
    url: '/sys/user/admin/export',
    method: 'get',
    responseType: 'blob',
    params: query
  })
}

// 查询用户详细
export function getUser(userId) {
  return request({
    url: '/sys/user/admin/info/' + praseStrEmpty(userId),
    method: 'get'
  })
}

// 删除用户
export function delUser(id) {
  return request({
    url: '/sys/user/admin/remove',
    method: 'delete',
    data: {
      "ids": id
    }
  })
}

// 用户密码重置
export function resetUserPwd(id, pwd) {
  const data = {
    id,
    pwd
  }
  return request({
    url: '/sys/user/admin/resetUserPwd',
    method: 'put',
    data: data
  })
}

// 用户状态修改
export function changeUserStatus(id, status) {
  const data = {
    id,
    status
  }
  return request({
    url: '/sys/user/admin/updateStatus',
    method: 'put',
    data: data
  })
}